from Autotests.WebDriver import DRIVER
from Autotests.LocalMachine.Controls.BaseControl import BaseWebControl
from Config.RunConfig import RunConfig, Options


class BaseWebPage(BaseWebControl):
    def __init__(self, handler):
        super(BaseWebPage, self).__init__(handler)

    def goToHomeLocation(self):
        DRIVER().get(RunConfig().get(Options.AirBackup.clientAddress))

    def save(self):
        pass

    def cancel(self):
        pass

    def exit(self):
        self.cancel()

    @staticmethod
    def setter(func):
        def _decorator(self, *args, **kwargs):
            self.goToHomeLocation()
            result = func(self, *args, **kwargs)
            self.save()
            return result
        return _decorator

    @staticmethod
    def getter(func):
        def _decorator(self, *args, **kwargs):
            self.goToHomeLocation()
            result = func(self, *args, **kwargs)
            self.exit()
            return result
        return _decorator


class BaseWebManagerPage(BaseWebPage):
    def __init__(self, handler):
        super(BaseWebManagerPage, self).__init__(handler)

    def goToHomeLocation(self):
        DRIVER().get(RunConfig().get(Options.AirBackup.managerAddress))